package yf.mall.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import java.util.Map;
import com.yf.consts.DaoConst;
import yf.mall.entity.ShopEntity;
import yf.mall.service.ShopService;
import com.yf.response.R;


/**
 * 店铺Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Sun May 24 13:54:38 CST 2020
 */
@RestController
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    private ShopService shopService;

    /**
     * 列表店铺
     */
    @RequestMapping("/list")
    @RequiresPermissions("shop:list")
    public R list(@RequestParam Map<String,Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<ShopEntity> shopList = shopService.queryList(params);
        return R.ok(new PageInfo(shopList));
    }

    /**
     * 查看店铺
     */
    @SysLog("查看店铺")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("shop:info")
    public R info(@PathVariable("id") Long id) {
        ShopEntity shop = shopService.get(id);

        return R.ok(shop);
    }

    /**
     * 保存店铺
     */
    @SysLog("保存店铺")
    @RequestMapping("/save")
    @RequiresPermissions("shop:save")
    public R save(ShopEntity shop) {
        shopService.save(shop);

        return R.ok(shop);
    }

    /**
     * 修改店铺
     */
    @SysLog("修改店铺")
    @RequestMapping("/update")
    @RequiresPermissions("shop:update")
    public R update(ShopEntity shop) {
        shopService.update(shop);

        return R.ok(shop);
    }

    /**
     * 删除店铺
     */
    @SysLog("删除店铺")
    @RequestMapping("/delete")
    @RequiresPermissions("shop:delete")
    public R delete(Long[]ids) {
        shopService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有店铺
     */
    @SysLog("所有店铺")
    @RequestMapping("/queryAll")
    public R queryAll (@RequestParam Map<String,Object> params) {

        List<ShopEntity> shopList = shopService.queryList(params);

        return R.ok(shopList);
    }

    /**
    @ModelAttribute
    public SearchParam<ShopEntity> searchParam(SearchParam<ShopEntity> params, ShopEntity shop) {
        if (shop != null) {
            params.setEntity(shop);
        }

        return params;
    }
 **/
    /***********自定义开始***********/
}
